home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / ClutFade 1.3.2 / C / FadeTester Source / Shell.c < prev    next >
C/C++ Source or Header  |  1996-05-08  |  5KB  |  208 lines

  1. /********************************************************************************
  2.  
  3.      PROJECT:    clut_fade.π
  4.      
  5.      FILE:        shell.c
  6.      
  7.      PURPOSE:    'clut' fading functions
  8.      
  9.      STATUS:        Public Domain Demo.
  10.  
  11.  ********************************************************************************/
  12.  
  13. //=================================    INCLUDES ====================================
  14.  
  15. #include "shell.h"
  16. #include "fade.h"
  17.  
  18. //=================================    FUNCTIONS ===================================
  19.  
  20. void init_toolbox(void);
  21. void test_window(void);
  22.  
  23.  
  24. /*********************************** main ***************************************/
  25. extern
  26. void main(void)
  27. {
  28.     init_toolbox();
  29.     test_window();    
  30. }
  31. /*** main ***/
  32.  
  33. /********************************** init_toolbox ********************************/
  34. static
  35. void init_toolbox(void)
  36. {
  37.     MaxApplZone();
  38.     MoreMasters();
  39.     InitGraf(&qd.thePort);
  40.     InitFonts();
  41.     InitWindows();
  42.     InitMenus();
  43.     TEInit();
  44.     InitDialogs(nil);
  45.     InitCursor();
  46.     FlushEvents(everyEvent, 0);
  47. }
  48. /*** init_toolbox ***/
  49.  
  50. /********************************** test_window *********************************/
  51. static
  52. void test_window(void)
  53. {
  54.     DialogPtr    d;
  55.     GrafPtr        g;
  56.     short        hit;
  57.     GDHandle    hGD;
  58.     CTabHandle    hCTab;
  59.     long         ticks;
  60.     short         fadeSpeed;
  61.     Handle        iHandle;
  62.     short        iType;
  63.     Rect        iRect;
  64.     
  65.     if (d = GetNewDialog(128, nil, (WindowPtr) -1L))
  66.     {
  67.         GetPort(&g);
  68.         SetPort(d);
  69.         ShowWindow(d);
  70.         
  71.         do
  72.         {
  73.             ModalDialog(nil, &hit);
  74.             GetDItem(d,10,&iType,&iHandle,&iRect);
  75.             fadeSpeed = GetCtlValue((ControlHandle)iHandle);
  76.             switch (hit)
  77.             {
  78.                 // fade all monitors to black
  79.                 case    2:
  80.                     // fade out
  81.                     fade_to_black(fadeSpeed, fadeAll, true);
  82.                     // wait a few seconds
  83.                     Delay (120L, &ticks);
  84.                     // fade in
  85.                     fade_to_black(fadeSpeed, fadeAll, false);
  86.                     break;
  87.  
  88.                 // fade main monitor to black
  89.                 case    3:
  90.                     // fade out
  91.                     fade_to_black(fadeSpeed, fadeMainOnly, true);
  92.                     // wait a few seconds
  93.                     Delay (120L, &ticks);
  94.                     // fade in
  95.                     fade_to_black(fadeSpeed, fadeMainOnly, false);
  96.                     break;
  97.                     
  98.                 // fade all monitors except main monitor to black
  99.                 case    4:
  100.                     // fade out
  101.                     fade_to_black(fadeSpeed, fadeAllButMain, true);
  102.                     // wait a few seconds
  103.                     Delay (120L, &ticks);
  104.                     // fade in
  105.                     fade_to_black(fadeSpeed, fadeAllButMain, false);
  106.                     break;
  107.                     
  108.                 // fade main monitor to red
  109.                 case    5:
  110.                     {
  111.                     CTabHandle    origColors;
  112.                     GDHandle    mainDevice = GetMainDevice();
  113.                     RGBColor    aColor;
  114.                         
  115.                         // make a copy of the color table so we can restore it later
  116.                         copy_gdevice_clut(mainDevice,&origColors);
  117.                         
  118.                         // fade to a color
  119.                         aColor.red = 65535;
  120.                         aColor.green = 0;
  121.                         aColor.blue = 0;
  122.                         fade_to_color(fadeSpeed,&aColor,mainDevice);
  123.                         
  124.                         // wait a few seconds
  125.                         Delay (120L, &ticks);
  126.                         
  127.                         // fade back to original color table
  128.                         fade_to_clut(fadeSpeed,origColors,mainDevice);
  129.  
  130.                         // dispose the copy we made
  131.                         DisposeHandle((Handle)origColors);
  132.                     }
  133.                     break;
  134.  
  135.                 // fade main monitor through rainbow
  136.                 case    6:
  137.                     {
  138.                     CTabHandle    origColors;
  139.                     CTabHandle    newColors;
  140.                     short        x;
  141.                     GDHandle    mainDevice = GetMainDevice();
  142.                         
  143.                         // make a copy of the color table so we can restore it later
  144.                         copy_gdevice_clut(mainDevice,&origColors);
  145.                         
  146.                         for (x = 128; x < 135; x++)
  147.                         {
  148.                             // get a custom color table (red or blue)
  149.                             newColors = GetCTable(x);
  150.                             // limit it to current depth
  151.                             (**newColors).ctSize = (**origColors).ctSize;
  152.                             // resize the handle
  153.                             SetHandleSize((Handle)newColors, GetHandleSize((Handle)origColors));
  154.                             // fade to the custow color table
  155.                             fade_to_clut(40,newColors,mainDevice);
  156.                             ReleaseResource((Handle)newColors);
  157.                         }
  158.  
  159.                         // fade back to original color table
  160.                         fade_to_clut(40,origColors,mainDevice);
  161.                         // dispose the copy we made
  162.                         DisposeHandle((Handle)origColors);
  163.                     }
  164.                     break;
  165.                     
  166.                 // fade to inverted clut
  167.                 case    7:
  168.                     {
  169.                     CTabHandle    origColors;
  170.                     CTabHandle    newColors;
  171.                     RGBColor    aColor;
  172.                     short        x;
  173.                     GDHandle    mainDevice = GetMainDevice();
  174.                         
  175.                         // make a copy of the color table so we can restore it later
  176.                         copy_gdevice_clut(mainDevice,&origColors);
  177.                         // make a copy of the color table so we manipulate it
  178.                         copy_gdevice_clut(mainDevice,&newColors);
  179.                         // reverse order of colors for a fun effect
  180.                         for (x = 0; x < (((**newColors).ctSize+1)/2); x++)
  181.                         {
  182.                             aColor = (**newColors).ctTable[x].rgb;
  183.                             (**newColors).ctTable[x].rgb = (**newColors).ctTable[(**newColors).ctSize - x].rgb;
  184.                             (**newColors).ctTable[(**newColors).ctSize - x].rgb = aColor;
  185.                         }
  186.                         // change the ctSeed so we know it is different than original
  187.                         (**newColors).ctSeed = GetCTSeed();
  188.                         // fade to it
  189.                         fade_to_clut(fadeSpeed,newColors,mainDevice);
  190.                         // wait a few seconds
  191.                         Delay (120L, &ticks);
  192.                         // fade back to original color table
  193.                         fade_to_clut(fadeSpeed,origColors,mainDevice);
  194.                         // dispose the copy we made
  195.                         DisposeHandle((Handle)origColors);
  196.                     }
  197.                     break;
  198.             }
  199.         }
  200.         while (hit != 1);
  201.         
  202.         SetPort(g);
  203.         DisposDialog(d);
  204.     }
  205. }
  206. /*** test_window ***/
  207.  
  208. //===================================== EOF =====================================